package name.fowler.refactoring.simplestore.service;

import name.fowler.refactoring.simplestore.model.Customer;
import name.fowler.refactoring.simplestore.model.Movie;
import name.fowler.refactoring.simplestore.model.Rental;

class TextReportFormatter extends ReportFormatter {

    private static final String HEADER = "Rental record for %s\n";
    private static final String MOVIE_RECORD = "\t%s\t%s\n";
    private static final String FOOTER = "Amount owed is %s \nYou earned %s frequent renter points.";

    @Override
    protected String formatHeader(Customer customer) {
        return String.format(HEADER, customer.getName());
    }

    @Override
    protected String formatBody(Customer customer) {
        StringBuilder sbBody = new StringBuilder();
        for (Rental rental : customer.getRentals()) {
            for (Movie movie : rental.getMovies()) {
                sbBody.append(String.format(MOVIE_RECORD, movie.getTitle(), movie.getPriceCode().getAmount(rental.getDaysRented())));
            }
        }
        return sbBody.toString();
    }

    @Override
    protected String formatFooter(Customer customer) {
        return String.format(FOOTER, customer.getTotalAmount(), customer.getTotalBonus());
    }
}
